Skip to content

Add home dashboard usage insights#553

Open
Samigos wants to merge 4 commits intoDimillian:mainfrom
Samigos:enhance-statistics
Open

Add home dashboard usage insights#553
Samigos wants to merge 4 commits intoDimillian:mainfrom
Samigos:enhance-statistics

Conversation

@Samigos
Copy link
Contributor

@Samigos Samigos commented Mar 13, 2026

Summary

  • expand the home usage snapshot with more token and time metrics, streak and activity insights, and week-by-week chart navigation
  • surface account limits, credits, and plan details on the home dashboard
  • wire the new account data into the home surface and add coverage for the expanded dashboard states

Testing

  • npm run typecheck
  • npm run test

Screenshot

Home dashboard usage snapshot

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f55e3a931

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +606 to +609
accountRateLimits: activeRateLimits,
usageShowRemaining: appSettings.usageShowRemaining,
accountInfo: activeAccount,
accountWorkspaceLabel: activeWorkspace?.name ?? null,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Source home account cards from home-visible workspace state

These props are wired from activeRateLimits/activeAccount, but on the Home screen we clear activeWorkspaceId (src/features/workspaces/hooks/useWorkspaceSelection.ts), and MainApp.tsx derives both values from activeWorkspaceId, so they become null in the exact context where this dashboard is shown. As a result, Home never gets rate-limit/account data and accountCards stays empty, so the new “Account limits” section does not render in normal Home usage; this should be sourced from the workspace selection used by Home (or another home-specific account source) instead of active-thread workspace state.

Useful? React with 👍 / 👎.

@Samigos
Copy link
Contributor Author

Samigos commented Mar 13, 2026

Not ready yet... don’t merge 😁

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03a974bae2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +228 to +232
aggregateHomeAccountSelection.isCommitted &&
canRetainAggregateHomeAccountWorkspaceId(
aggregateHomeAccountSelection.workspaceId,
workspaces,
rateLimitsByWorkspace,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain home account workspace while account data is pending

When Home is in “All workspaces” mode and no workspace has a usable account/rate-limit snapshot yet (common right after startup or when auth returns placeholder data), this retention gate fails and stableHomeAccountWorkspaceId falls back to resolveHomeAccountWorkspaceId on each thread-activity reorder. That makes the selected account workspace bounce between projects and repeatedly re-triggers the refresh effect (refreshAccountInfo/refreshAccountRateLimits) for different workspaces, creating avoidable RPC churn and unstable Home/Sidebar account data until one workspace happens to return usable data.

Useful? React with 👍 / 👎.

@Samigos
Copy link
Contributor Author

Samigos commented Mar 14, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03a974bae2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +107 to +111
return workspaceHasAccountData(
workspace,
rateLimitsByWorkspace,
accountByWorkspace,
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop retaining disconnected workspace for Home account limits

In aggregate Home mode (usageWorkspaceId === null), canRetainAggregateHomeAccountWorkspaceId only checks whether cached account/rate-limit data exists and ignores workspace.connected. If the previously selected workspace disconnects, this returns true, so stableHomeAccountWorkspaceId keeps pointing at a disconnected workspace and the refresh effect no longer runs (homeAccountWorkspace?.connected gate), leaving stale limits visible even though another connected workspace is available. This conflicts with resolveHomeAccountWorkspaceId, which explicitly prioritizes connected workspaces.

Useful? React with 👍 / 👎.

Comment on lines +353 to +355
value: formatCompactNumber(usageTotals?.last30DaysTokens ?? last7Tokens),
suffix: "tokens",
caption: `Total ${formatCount(usageTotals?.last30DaysTokens ?? last7Tokens)}`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Use a 30-day fallback when totals are missing

The "Last 30 days" token card falls back to last7Tokens when usageTotals?.last30DaysTokens is unavailable, so partial/older snapshot payloads underreport the 30-day total as a 7-day value. Since this component already defensively handles missing totals fields, this fallback should use a 30-day aggregate from usageDays rather than the 7-day sum.

Useful? React with 👍 / 👎.

@Samigos
Copy link
Contributor Author

Samigos commented Mar 14, 2026

@Dimillian I think we are good to go on this one.

Copy link

@xkonjin xkonjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Feature PR adding usage insights to the home dashboard. The test coverage is commendably deep — 529 lines of hook tests plus Sidebar tests for the credits display. A few issues to flag:

Logic concerns

resolveHomeAccountWorkspaceId fallback ordering: When usageWorkspaceId is set but doesn't match any workspace (the "missing" case in tests), the function falls back to a heuristic. The tests assert specific ordering (connected > disconnected, most recent activity, real account over unknown type) but the production fallback logic isn't visible in this diff. It's important that the ranking is deterministic when two workspaces have identical updatedAt timestamps — undefined sort order here could cause the home dashboard to flicker between workspaces across renders.

inferredHasCredits in normalizeCreditsSnapshot: The new inference logic sets hasCredits: true when normalizedBalance is a non-empty string. This means a balance of "0" would set hasCredits: true, which is semantically wrong — zero credits means no usable credits. Consider changing the inference to parseFloat(normalizedBalance) > 0 or only relying on the explicit hasCredits field. The existing keeps credit balances visible when unlimited is explicitly false test uses balance "120" so it wouldn't catch this edge case.

Numeric balance normalization: typeof balanceRaw === "number" && Number.isFinite(balanceRaw) won't handle NaN (which passes typeof === "number" but fails isFinite). The guard is correct but the else branch falls through to previousCredits?.balance ?? null, which is probably fine — just worth an explicit test for balance: NaN to document the intended behavior.

Test gaps

  • No test for balance: "0" — the inferred hasCredits bug described above.
  • No test for concurrent workspace refresh (both refreshAccountInfo and refreshAccountRateLimits called in the same tick) to verify no double-render or stale closure issues.
  • The Sidebar.test.tsx snapshot test for credits checks screen.getByText("Available credits: 120") — if the number formatting ever changes (e.g., locale-aware "120.00" or ""), this will silently break. Consider a more resilient matcher.

CSS

The is-up / is-down gradient backgrounds look fine. One potential issue: var(--text-accent) for the is-up color — if that's a blue accent on a blue-tinted gradient background (rgba(88, 190, 255, 0.18)), the contrast ratio may fall below WCAG AA. Worth a quick accessibility check with the actual theme colors.

Minor

  • The screenshot in docs/screenshots/ is committed as a binary file — if this directory isn't gitignored, it'll bloat the repo history on every dashboard update. Consider linking to an external asset or using git-lfs.

Overall: good feature with strong test coverage. The inferredHasCredits zero-balance edge case and deterministic workspace sorting are the highest-priority issues before merge.

@Samigos
Copy link
Contributor Author

Samigos commented Mar 14, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01433c46a7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +107 to +111
return workspaceHasAccountData(
workspace,
rateLimitsByWorkspace,
accountByWorkspace,
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require connectivity when retaining aggregate home account

The retention guard for committed aggregate selection only checks whether cached account/rate-limit data exists, not whether that workspace is still connected. In the All workspaces flow, this can lock the Home account source onto a disconnected workspace (for example after startup with stale cached data), and because refresh is skipped for disconnected workspaces, account limits can stay stale even after another workspace connects and has current data.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants